package com.cy.service.impl;

import com.cy.common.ResultResponse;
import com.cy.entity.Courses;
import com.cy.entity.Documents;
import com.cy.entity.Users;
import com.cy.mapper.DocumentsMapper;
import com.cy.service.IDocumentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Aleven
 * @since 2024-12-21
 */
@Service
public class DocumentsServiceImpl extends ServiceImpl<DocumentsMapper, Documents> implements IDocumentsService {

    @Autowired
    private DocumentsMapper documentsMapper ;


    //查询所有文档
    @Override
    public List<Documents> FindAllDocuments(){return documentsMapper.FindAllDocuments();}

    //根据条件查询文档
    @Override
    public List<Documents> FindByCondition(Documents documents){return documentsMapper.FindByCondition(documents);}


    //增加文档
    @Override
    public ResultResponse insertDocuments(Documents documents) throws Exception {
        if (documents.getDocumentType() == null || documents.getDocumentURL() == null
        || documents.getCourseID() == null){
            return ResultResponse.fail("请把信息输入全");
        }

        int count = documentsMapper.insertDocuments(documents);
        return count>0?ResultResponse.success():ResultResponse.fail();
    }


    //修改文档
    @Override
    public  ResultResponse updateDocuments(@RequestBody Documents documents) throws Exception{
        if (documents.getDocumentType() == null || documents.getDocumentURL() == null
                || documents.getCourseID() == null){
            return ResultResponse.fail("请把信息输入全");
        }

        int count = documentsMapper.updateDocuments(documents);
        return count>0?ResultResponse.success():ResultResponse.fail();
    }


    //删除文档
    @Override
    public int delDocuments(String DocumentID){return documentsMapper.delDocuments(DocumentID);}







}
